import java.util.HashMap;

public class FlyweightFactory {
    //享元池
    private HashMap<String, Flyweight>flyweights= new HashMap<String, Flyweight>();

    public Flyweight getFlyweight(String key){
        Flyweight flyweight;
        if(flyweights.containsKey(key)){
            flyweight = flyweights.get(key);
        }else{ //如果池中没有，就创建一个
            flyweight=new ConcreteFlyweight(key);
            flyweights.put(key,flyweight);
        }
        return flyweight;
    }

}
